<template>
<div>
    <el-form :model="formData" label-position="right" label-width="80px">
             <el-form-item label="选品ID:"><el-input v-model.number="formData.selectGoodsId" clearable placeholder="请输入"></el-input>
          </el-form-item>
           
             <el-form-item label="一级类目:">
                <el-input v-model="formData.categoryFirst" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="二级类目:">
                <el-input v-model="formData.categorySecond" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="图片:">
                <el-input v-model="formData.imageUrl" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="供应商:">
                <el-input v-model="formData.supplier" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="进价:">
                  <el-input-number v-model="formData.purchasePrice" :precision="2" clearable></el-input-number>
           </el-form-item>
           
             <el-form-item label="预售价:">
                  <el-input-number v-model="formData.preSalePrice" :precision="2" clearable></el-input-number>
           </el-form-item>
           
             <el-form-item label="卖点:">
                <el-input v-model="formData.sellPoint" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="竞品:">
                <el-input v-model="formData.competitiveProducts" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           
             <el-form-item label="竞品售价:">
                  <el-input-number v-model="formData.competitiveSellPrice" :precision="2" clearable></el-input-number>
           </el-form-item>
           
             <el-form-item label="选品人:">
                <el-input v-model="formData.selectOwner" clearable placeholder="请输入" ></el-input>
          </el-form-item>
           <el-form-item>
           <el-button @click="save" type="primary">保存</el-button>
           <el-button @click="back" type="primary">返回</el-button>
           </el-form-item>
    </el-form>
</div>
</template>

<script>
import {
    createSelectList,
    updateSelectList,
    findSelectList
} from "@/api/selectList";  //  此处请自行替换地址
import infoList from "@/mixins/infoList";
export default {
  name: "SelectList",
  mixins: [infoList],
  data() {
    return {
      type: "",formData: {
            selectGoodsId:0,
            categoryFirst:"",
            categorySecond:"",
            imageUrl:"",
            supplier:"",
            purchasePrice:0,
            preSalePrice:0,
            sellPoint:"",
            competitiveProducts:"",
            competitiveSellPrice:0,
            selectOwner:"",
            
      }
    };
  },
  methods: {
    async save() {
      let res;
      switch (this.type) {
        case "create":
          res = await createSelectList(this.formData);
          break;
        case "update":
          res = await updateSelectList(this.formData);
          break;
        default:
          res = await createSelectList(this.formData);
          break;
      }
      if (res.code == 0) {
        this.$message({
          type:"success",
          message:"创建/更改成功"
        })
      }
    },
    back(){
        this.$router.go(-1)
    }
  },
  async created() {
   // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if(this.$route.query.id){
    const res = await findSelectList({ ID: this.$route.query.id })
    if(res.code == 0){
       this.formData = res.data.reselectList
       this.type = "update"
     }
    }else{
     this.type = "create"
   }
  
}
};
</script>

<style>
</style>